﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Control
{
    class Program
    {
        static void Main(string[] args)
        {
            //IncreaseValue();
            //SumOfValues();
            //DistanseBetweenTwoPoints();
            //DetermineQuarter();

            //DrawBorders(5, 4, '*');
            //GenerateRndArray(5);
            //GetCount();
            MinMaxCount();
        }


        public static void IncreaseValue()
        {
            Console.WriteLine("Enter value: ");
            int value = Int32.Parse(Console.ReadLine());
            Console.WriteLine("Result: ");
            Console.WriteLine(value + 10);
        }

        public static void SumOfValues()
        {
            Console.WriteLine("Enter the number of values: ");
            int number = Int32.Parse(Console.ReadLine());

            int sum = 0;
            if (number >= 0)
            {
                for (int i = 0; i < number + 1; i++)
                {
                    sum += i;
                }
                Console.WriteLine("Sum of {0} values from 0 to {0} is - {1}", number, sum);
            }
            else
            {
                Console.WriteLine("It was entered incorrect number ");
            }
        }

        public static void DistanseBetweenTwoPoints()
        {
            Console.WriteLine("Enter coordinates of first point:");
            Console.WriteLine("x:");
            double x1 = Int32.Parse(Console.ReadLine());
            Console.WriteLine("y:");
            double y1 = Int32.Parse(Console.ReadLine());
            Console.WriteLine("Enter coordinates of second point:");
            Console.WriteLine("x:");
            double x2 = Int32.Parse(Console.ReadLine());
            Console.WriteLine("y:");
            double y2 = Int32.Parse(Console.ReadLine());

            double side1 = x1-x2;
            double side2 = y1-y2;
            double c = Math.Sqrt(Math.Pow(side1, 2) + Math.Pow(side2, 2));
            c = Math.Round(c, 2);
            Console.WriteLine("Distance between first and second point is: {0}", c);
        }

        public static void DetermineQuarter()
        {
            Console.WriteLine("Enter coordinates of point:");
            Console.WriteLine("x:");
            int x = Int32.Parse(Console.ReadLine());
            Console.WriteLine("y:");
            int y = Int32.Parse(Console.ReadLine());

            if (x ==0 | y == 0)
            {
                Console.WriteLine("Point situated on the axis.");
            }
            else if (x>0 & y>0)
            {
                Console.WriteLine("Point situated on I axis.");
            }
            else if (x > 0 & y < 0)
            {
                Console.WriteLine("Point situated on IV axis.");
            }
            else if (x < 0 & y < 0)
            {
                Console.WriteLine("Point situated on III axis.");
            }
            else if (x < 0 & y > 0)
            {
                Console.WriteLine("Point situated on II axis.");
            }
        }

        public static void DrawBorders(int height, int lenght, char ch)
        {
            for (int j = 1; j <= height; j++)
            {
                for (int i = 1; i <= lenght; i++)
                {
                    if (i == 1 || i == lenght || j == 1 || j == height)  //добавила условие j == 1 || j == height 
                    {
                        Console.Write(ch);
                    }
                    else
                    {
                        Console.Write(' ');
                    } 
                }
                Console.WriteLine();
            }
        }

        public static int[] GenerateRndArray(int size)
        {
            Random rnd = new Random();
            int [] array = new int[size];
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = rnd.Next(0, 100);
                //Console.Write("{0} ", array[i]);
            }
            return array;
        }

        public static void GetCount ()
        {
            int[] inArray = GenerateRndArray(5);

            foreach (var el in inArray)
            {
                Console.WriteLine("{0} ", el);
            }
            int even = 0;
            int odd = 0;
            foreach (var el in inArray)
            {
                if ((el % 2) == 0)
                {
                    even++;
                }
                else if ((el % 2) != 0)
                    odd++;
            }
            Console.WriteLine("even count: {0}", even);
            Console.WriteLine("odd count: {0}", odd);
        }

        public static void MinMaxCount()
        {
            int[] inArray = GenerateRndArray(15);

            foreach (var el in inArray)
            {
                Console.WriteLine("{0} ", el);
            }
            int maxValue = inArray.Max(); 
            int minValue = inArray.Min();
            int minCount = 0;
            int maxCount = 0;
            foreach (int el in inArray)
            {
                if (el == minValue)
                    minCount++;
                else if (el == maxValue)
                    maxCount++;
            }
            Console.WriteLine("Min element is {0}, count {1}, index of first min value - {2}", minValue, minCount, Array.IndexOf(inArray, minValue));
            Console.WriteLine("Max element is {0}, count {1}, index of first max value - {2}", maxValue, maxCount, Array.IndexOf(inArray, maxValue));
            Console.WriteLine("Total minmax count {0} is ", minCount+maxCount);

        }
    }
}
